package com.boarsoft.boar.sequence.segment;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boarsoft.bean.ReplyInfo;
import com.boarsoft.boar.sequence.biz.SequenceSegmentBiz;
import com.boarsoft.boar.sequence.entity.SequenceSegment;
import com.boarsoft.common.Authorized;
import com.boarsoft.common.Util;
import com.boarsoft.common.dao.PagedResult;

@RestController
public class SequenceSegmentController {
	// private static final Logger log =
	// LoggerFactory.getLogger(SequenceSegmentController.class);

	@Autowired
	private SequenceSegmentBiz sequenceSegmentBiz;

	@Authorized(code = "sequence.segment.save")
	@RequestMapping("/sequence/segment/save.do")
	public ReplyInfo<Object> save(SequenceSegment form) {
		sequenceSegmentBiz.save(form);
		return new ReplyInfo<Object>();
	}

	@Authorized(code = "sequence.segment.update")
	@RequestMapping("/sequence/segment/update.do")
	public ReplyInfo<Object> update(SequenceSegment form) {
		SequenceSegment o = sequenceSegmentBiz.get(form.getId());
		o.setBeginNo(form.getBeginNo());
		o.setEndNo(form.getEndNo());
		o.setId(form.getId());
		o.setNode(form.getNode());
		o.setSequenceId(form.getSequenceId());
		sequenceSegmentBiz.save(o);
		return new ReplyInfo<Object>();
	}

	@Authorized(code = "sequence.segment.delete")
	@RequestMapping("/sequence/segment/delete.do")
	public ReplyInfo<Object> delete(String id) {
		if (Util.strIsEmpty(id)) {
			return new ReplyInfo<Object>("invalid");
		}
		sequenceSegmentBiz.delete(id);
		return new ReplyInfo<Object>();
	}

	@Authorized(code = "sequence.segment.list")
	@RequestMapping("/sequence/segment/list.do")
	public ReplyInfo<Object> list(String sequenceId, String orderBy, int pageNo, int pageSize) {
		PagedResult<SequenceSegment> pr = sequenceSegmentBiz.list(sequenceId, orderBy, pageNo, pageSize);
		return new ReplyInfo<Object>(pr);
	}

}
